<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.org/ui">

    <h:form id="PaisListForm">

        <p:panel header="#{myBundle.ListPaisTitle}">
            <p:contextMenu id="PaisDataTableContextMenu" for="datalist">  
                <p:menuitem value="#{myBundle.Create}" onclick="document.getElementById('PaisListForm:createButton').click();" icon="ui-icon-plus"/>
                <p:menuitem value="#{myBundle.View}" onclick="document.getElementById('PaisListForm:viewButton').click();" icon="ui-icon-search"/>
                <p:menuitem value="#{myBundle.Edit}" onclick="document.getElementById('PaisListForm:editButton').click();" icon="ui-icon-pencil"/>
                <p:menuitem value="#{myBundle.Delete}" onclick="document.getElementById('PaisListForm:deleteButton').click();" icon="ui-icon-trash"/>
                <p:separator/>
                <p:menuitem value="#{myBundle.PaisMenuItem_regionList}" icon="ui-icon-search"  action="#{paisController.navigateRegionList}" disabled="#{empty paisController.selected.regionList}" ajax="false"/>  
            </p:contextMenu>
            <p:dataTable id="datalist"
                         value="#{paisController.items}"
                         var="item"
                         rowKey="#{item.idPais}"
                         paginator="true"
                         rows="10"
                         rowsPerPageTemplate="10,20,30,40,50"
                         selectionMode="single"
                         selection="#{paisController.selected}">

                <p:ajax event="rowSelect"   update=":PaisListForm:createButton :PaisListForm:viewButton :PaisListForm:editButton :PaisListForm:deleteButton :PaisListForm:PaisDataTableContextMenu" listener="#{paisController.resetParents}"/>
                <p:ajax event="rowUnselect" update=":PaisListForm:createButton :PaisListForm:viewButton :PaisListForm:editButton :PaisListForm:deleteButton :PaisListForm:PaisDataTableContextMenu" listener="#{paisController.resetParents}"/>
                <p:ajax event="rowDblselect" onsuccess="document.getElementById('PaisListForm:viewButton').click();"/>

                <p:column sortBy="#{item.idPais}" filterBy="#{item.idPais}">
                    <f:facet name="header">
                        <h:outputText value="#{myBundle.ListPaisTitle_idPais}"/>
                    </f:facet>
                    <h:outputText value="#{item.idPais}"/>
                </p:column>


                <p:column sortBy="#{item.nombre}" filterBy="#{item.nombre}">
                    <f:facet name="header">
                        <h:outputText value="#{myBundle.ListPaisTitle_nombre}"/>
                    </f:facet>
                    <h:outputText value="#{item.nombre}"/>
                </p:column>


            </p:dataTable>

            <p:commandButton id="createButton"                             icon="ui-icon-plus"   value="#{myBundle.Create}" actionListener="#{paisController.prepareCreate}" update=":PaisCreateForm" oncomplete="PaisCreateDialog.show()"/>
            <p:commandButton id="viewButton"   style="visibility: hidden;" icon="ui-icon-search" value="#{myBundle.View}" update=":PaisViewForm" oncomplete="PaisViewDialog.show()" disabled="#{empty paisController.selected}"/>
            <p:commandButton id="editButton"   style="visibility: hidden;" icon="ui-icon-pencil" value="#{myBundle.Edit}" update=":PaisEditForm" oncomplete="PaisEditDialog.show()" disabled="#{empty paisController.selected}"/>
            <p:commandButton id="deleteButton" style="visibility: hidden;" icon="ui-icon-trash"  value="#{myBundle.Delete}" actionListener="#{paisController.delete}" update=":growl,datalist" disabled="#{empty paisController.selected}">
                <p:confirm header="#{myBundle.ConfirmationHeader}" message="#{myBundle.ConfirmDeleteMessage}" icon="ui-icon-alert"/>
            </p:commandButton>

        </p:panel>
        <ui:include src="/WEB-INF/include/confirmation.xhtml"/>
    </h:form>

</ui:composition>